import request from '@/config/axios'
import { getApiPath } from '@/config/api'

// 获取仪表盘数据
export function getDashboardData({ userId }) {
  console.log('Fetching dashboard data for userId:', userId)
  return request({
    url: '/api/dashboard',
    method: 'get',
    params: { 
      userId: Number(userId)  // 使用 Number 转换确保是数字
    }
  })
}

// 获取每日营养摄入数据
export function getDailyNutrition(date) {
  const userId = localStorage.getItem('userId')
  return request({
    url: getApiPath('DAILY_NUTRITION'),
    method: 'get',
    params: { 
      userId,
      date 
    }
  })
}

// 获取体重变化趋势
export function getWeightTrend(params) {
  const userId = localStorage.getItem('userId')
  return request({
    url: getApiPath('WEIGHT_TREND'),
    method: 'get',
    params: {
      userId: parseInt(userId),  // 确保 userId 是数字类型
      range: params.range || 'week'  // 默认获取一周的数据
    }
  })
}

// 获取目标完成进度
export function getGoalProgress() {
  const userId = localStorage.getItem('userId')
  return request({
    url: getApiPath('GOAL_PROGRESS'),
    method: 'get',
    params: { userId }
  })
}

// 获取最近膳食记录
export function getRecentMeals(params) {
  const userId = localStorage.getItem('userId')
  return request({
    url: getApiPath('RECENT_MEALS'),
    method: 'get',
    params: {
      ...params,
      userId
    }
  })
} 